<template>
  <!-- 搜索详情页 -->
  <div class="searchBox">
    <!-- 标题 -->
    <x-header :left-options="{showBack: true,backText:''}" class="headerBox">
      <div class="searchBtn">
        <div class="searchInner flex">
          <x-icon type="ios-search-strong" size="22" class="searchIcon"></x-icon>
          <input
            type="text"
            class="searchInput"
            v-model="keyWord"
            placeholder="搜索内容"
            @keyup.enter="searchClick"
          />
        </div>
      </div>
      <div slot="right" class="headRight" @click="searchClick">搜索</div>
    </x-header>
    <div class="hotLog">
      <div class="search-keywords bor-b" id="hotwords">
        <div class="headTop">热门搜索</div>
        <div class="searchLog clearfix">
          <router-link to v-for="(item,index) in hotSearch" :key="index" class="searchItem">{{item}}</router-link>
        </div>
      </div>
    </div>
    <!-- 历史记录 -->
    <div v-if="log.length>0" class="hotLog history">
      <div class="search-keywords bor-b" id="hotwords">
        <div class="headTop flex_sb">
          历史记录
          <img src="../assets/images/del.png" alt @click="deletBtn" />
        </div>
        <div class="searchLog clearfix">
          <router-link to v-for="(item,index) in log" :key="index" class="searchItem">{{item}}</router-link>
        </div>
      </div>
    </div>
    <confirm v-model="showHint" title="温馨提示" @on-confirm="onConfirm">
      <div>确定要删除记录吗?</div>
    </confirm>
  </div>
</template>

<script>
import { XHeader, Confirm } from 'vux'
import Bus from '@/js/bus.js'
export default {
  components: {
    XHeader,
    Confirm
  },
  data() {
    return {
      keyWord: '',
      showHint: false,
      hotSearch: ['手机', '电视', '冰箱', '洗衣机', '笔记本', '口红', '运动鞋', '羽绒服',],
      log: []
    }
  },
  created() {
    Bus.$on('link', (res) => {
      this.keyWord = res
      this.searchClick()
    })
  },
  methods: {
    searchClick() {
      this.$vux.alert.show({
        content: '搜索触发'
      })
      this.log.push(this.keyWord)
    },
    deletBtn() {
      this.showHint = true
    },
    onConfirm() {

    }
  }
}
</script>

<style lang="less" scoped>
.searchBox {
  font-size: 24px;
  background-color: #fff;
  // 头部导航
  /deep/.headerBox {
    background-color: #fff;
    border-bottom: 1px solid #eee;
    // position: fixed;
    // top:0;
    // left: 0;
    // right: 0;
    // 搜索
    .searchBtn {
      padding: 0 20px;
      margin-top: 10px;
      .searchInner {
        background-color: #f5f5f5;
        border-radius: 10px;
        padding: 10px 20px;
        .searchIcon {
          fill: #6c6c6c;
          margin-right: 10px;
        }
        .searchInput {
          outline: none;
          border: none;
          background-color: #f5f5f5;
        }
      }
    }

    .vux-header-left {
      left: 24px;
      .vux-header-back {
        color: #000;
      }
      .left-arrow:before {
        border-color: #000;
      }
    }
    .vux-header-title {
      color: #000;
      margin: 0 80px;
    }
    .vux-header-right {
      color: #000;
      .headRight {
        margin-right: -10px;
        img {
          width: 40px;
        }
      }
    }
  }
  .hotLog {
    border-bottom: 1px solid #cccccc;
    .search-keywords {
      padding: 20px;
      .headTop {
        height: 80px;
        line-height: 80px;
        color: #999;
        font-size: 34px;
        position: relative;
        padding: 0;
        margin-bottom: 0;
        img {
          width: 24px;
        }
      }
      .searchLog {
        .searchItem {
          float: left;
          width: 31.5%;
          margin: 10px 2.7% 5px 0;
          height: 60px;
          background: #f2f2f2;
          font-size: 30px;
          line-height: 60px;
          border-radius: 5px;
          word-break: keep-all;
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
          text-align: center;
          color: #333;
        }
        .searchItem:nth-child(3n) {
          margin: 10px 0 5px 0;
        }
      }
    }
  }
  .hotLog.history {
    border-bottom: none;
  }
}
</style>